﻿using System;
using System.Windows.Forms;
using System.Windows.Input;
using Avivo.Tools.Sprite.Models;

namespace Avivo.Tools.Sprite
{
	public class BrowseCommand : ICommand
	{
		#region Private members
		private SpriteViewModel parent;
		#endregion

		#region Constructor
		public BrowseCommand(SpriteViewModel parent)
		{
			this.parent = parent;
		}
		#endregion

		#region Public properties
		public bool IsBrowseForOutputDirectory
		{
			get;
			set;
		}
		#endregion

		#region ICommand Members
		public bool CanExecute(object parameter)
		{
			return true;
		}

		public event EventHandler CanExecuteChanged;

		public void Execute(object parameter)
		{
			FolderBrowserDialog dialog = new FolderBrowserDialog();
			dialog.SelectedPath = (this.IsBrowseForOutputDirectory ? this.parent.OutputDirectory : this.parent.InputDirectory);
			dialog.Description = "Select a folder with templates.";
			dialog.ShowNewFolderButton = false;
			var result = dialog.ShowDialog();
			if (result == DialogResult.OK)
			{
				if (this.IsBrowseForOutputDirectory)
				{
					this.parent.OutputDirectory = dialog.SelectedPath;
				}
				else
				{
					this.parent.InputDirectory = dialog.SelectedPath;
				}
			}
		}
		#endregion
	}
}
